Class Thread {Java}

Documentation

* A <i>thread</i> is a thread of execution in a program. The Java
* Virtual Machine allows an application to have multiple threads of
* execution running concurrently.
* <p>
* Every thread has a priority. Threads with higher priority are
* executed in preference to threads with lower priority. Each thread
* may or may not also be marked as a daemon. When code running in
* some thread creates a new <code>Thread</code> object, the new
* thread has its priority initially set equal to the priority of the
* creating thread, and is a daemon thread if and only if the
* creating thread is a daemon.
* <p>
* When a Java Virtual Machine starts up, there is usually a single
* non-daemon thread (which typically calls the method named
* <code>main</code> of some designated class). The Java Virtual
* Machine continues to execute threads until either of the following
* occurs:
* <ul>
* <li>The <code>exit</code> method of class <code>Runtime</code> has been
* called and the security manager has permitted the exit operation
* to take place.
* <li>All threads that are not daemon threads have died, either by
* returning from the call to the <code>run</code> method or by
* performing the <code>stop</code> method.
* </ul>
* <p>
* There are two ways to create a new thread of execution. One is to
* declare a class to be a subclass of <code>Thread</code>. This
* subclass should override the <code>run</code> method of class
* <code>Thread</code>. An instance of the subclass can then be
* allocated and started. For example, a thread that computes primes
* larger than a stated value could be written as follows:
* <p><hr><blockquote><pre>
* class PrimeThread extends Thread {
* long minPrime;
* PrimeThread(long minPrime) {
* this.minPrime = minPrime;
* }
*
* public void run() {
* // compute primes larger than minPrime
* &nbsp;.&nbsp;.&nbsp;.
* }
* }
* </pre></blockquote><hr>
* <p>
* The following code would then create a thread and start it running:
* <p><blockquote><pre>
* PrimeThread p = new PrimeThread(143);
* p.start();
* </pre></blockquote>
* <p>
* The other way to create a thread is to declare a class that
* implements the <code>Runnable</code> interface. That class then
* implements the <code>run</code> method. An instance of the class can
* then be allocated, passed as an argument when creating
* <code>Thread</code>, and started. The same example in this other
* style looks like the following:
* <p><hr><blockquote><pre>
* class PrimeRun implements Runnable {
* long minPrime;
* PrimeRun(long minPrime) {
* this.minPrime = minPrime;
* }
*
* public void run() {
* // compute primes larger than minPrime
* &nbsp;.&nbsp;.&nbsp;.
* }
* }
* </pre></blockquote><hr>
* <p>
* The following code would then create a thread and start it running:
* <p><blockquote><pre>
* PrimeRun p = new PrimeRun(143);
* new Thread(p).start();
* </pre></blockquote>
* <p>
* Every thread has a name for identification purposes. More than
* one thread may have the same name. If a name is not specified when
* a thread is created, a new name is generated for it.
*
* @author unascribed
* @version 1.69, 02/20/97
* @see java.lang.Runnable
* @see java.lang.Runtime#exit(int)
* @see java.lang.Thread#run()
* @see java.lang.Thread#stop()
* @since JDK1.0


Parent Packagejava.langAbstractNo
Export ControlPublicAccessLink Class forNone
Class KindNormalClassCardinalityn
Space ConcurrencySequential
PersistenceNo


Operations
NameSignatureClass
nextThreadNumint nextThreadNum ()Thread
currentThreadThread currentThread ()Thread
yieldvoid yield ()Thread
sleepvoid sleep (long millis)Thread
sleepvoid sleep (long millis, int nanos)Thread
initvoid init (ThreadGroup g, Runnable target, String name)Thread
Thread Thread ()Thread
Thread Thread (Runnable target)Thread
Thread Thread (ThreadGroup group, Runnable target)Thread
Thread Thread (String name)Thread
Thread Thread (ThreadGroup group, String name)Thread
Thread Thread (Runnable target, String name)Thread
Thread Thread (ThreadGroup group, Runnable target, String name)Thread
startvoid start ()Thread
runvoid run ()Thread
exitvoid exit ()Thread
stopvoid stop ()Thread
stopvoid stop (Throwable o)Thread
interruptvoid interrupt ()Thread
interruptedboolean interrupted ()Thread
isInterruptedboolean isInterrupted ()Thread
isInterruptedboolean isInterrupted (boolean ClearInterrupted)Thread
destroyvoid destroy ()Thread
isAliveboolean isAlive ()Thread
suspendvoid suspend ()Thread
resumevoid resume ()Thread
setPriorityvoid setPriority (int newPriority)Thread
getPriorityint getPriority ()Thread
setNamevoid setName (String name)Thread
getNameString getName ()Thread
getThreadGroupThreadGroup getThreadGroup ()Thread
activeCountint activeCount ()Thread
enumerateint enumerate (Thread tarray[])Thread
countStackFramesint countStackFrames ()Thread
joinvoid join (long millis)Thread
joinvoid join (long millis, int nanos)Thread
joinvoid join ()Thread
dumpStackvoid dumpStack ()Thread
setDaemonvoid setDaemon (boolean on)Thread
isDaemonboolean isDaemon ()Thread
checkAccessvoid checkAccess ()Thread
toStringString toString ()Thread
setPriority0void setPriority0 (int newPriority)Thread
stop0void stop0 (Object o)Thread
suspend0void suspend0 ()Thread
resume0void resume0 ()Thread
interrupt0void interrupt0 ()Thread


Attributes
NameClassTypeInitial Value
name[]Threadchar
priorityThreadint
PrivateInfoThreadint
eetopThreadint
single_stepThreadboolean
daemonThreadbooleanfalse
stillbornThreadbooleanfalse
threadInitNumberThreadint
initial_stack_memoryThreadint
MIN_PRIORITYThreadint1
NORM_PRIORITYThreadint5
MAX_PRIORITYThreadint10


Associations
NameMy RoleMy ClassOther RoleOther Element
--Not Named----Not Named--Thread--Not Named--OfferingCache
--Not Named----Not Named--Thread--Not Named--CourseCache



Property Settings

Java
GenerateFinalizerFalseGenerateStaticInitializerFalse
GenerateInstanceInitializerFalseGenerateDefaultConstructorFalse
FinalFalseConstructorIspublic
Ctor_Setpublic, protected, private, packageStaticFalse